package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarEvaluation;
import com.ruoyi.car.service.ICarEvaluationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卖车评估（卖车-评估结果页）Controller
 * 
 * @author yby
 * @date 2025-09-02
 */
@RestController
@RequestMapping("/car/evaluation")
public class CarEvaluationController extends BaseController
{
    @Autowired
    private ICarEvaluationService carEvaluationService;

    /**
     * 查询卖车评估（卖车-评估结果页）列表
     */
    @PreAuthorize("@ss.hasPermi('car:evaluation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarEvaluation carEvaluation)
    {
        startPage();
        List<CarEvaluation> list = carEvaluationService.selectCarEvaluationList(carEvaluation);
        return getDataTable(list);
    }

    /**
     * 导出卖车评估（卖车-评估结果页）列表
     */
    @PreAuthorize("@ss.hasPermi('car:evaluation:export')")
    @Log(title = "卖车评估（卖车-评估结果页）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarEvaluation carEvaluation)
    {
        List<CarEvaluation> list = carEvaluationService.selectCarEvaluationList(carEvaluation);
        ExcelUtil<CarEvaluation> util = new ExcelUtil<CarEvaluation>(CarEvaluation.class);
        util.exportExcel(response, list, "卖车评估（卖车-评估结果页）数据");
    }

    /**
     * 获取卖车评估（卖车-评估结果页）详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:evaluation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carEvaluationService.selectCarEvaluationById(id));
    }

    /**
     * 新增卖车评估（卖车-评估结果页）
     */
    @PreAuthorize("@ss.hasPermi('car:evaluation:add')")
    @Log(title = "卖车评估（卖车-评估结果页）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarEvaluation carEvaluation)
    {
        // 调试日志：检查接收到的数据
        System.out.println("=== 调试信息 ===");
        System.out.println("sellerId: " + carEvaluation.getSellerId());
        System.out.println("brandId: " + carEvaluation.getBrandId());
        System.out.println("seriesId: " + carEvaluation.getSeriesId());
        System.out.println("=== 调试结束 ===");
        
        // 如果sellerId为空，返回错误
        if (carEvaluation.getSellerId() == null) {
            return AjaxResult.error("请选择客户！sellerId不能为空");
        }
        
        return toAjax(carEvaluationService.insertCarEvaluation(carEvaluation));
    }

    /**
     * 修改卖车评估（卖车-评估结果页）
     */
    @PreAuthorize("@ss.hasPermi('car:evaluation:edit')")
    @Log(title = "卖车评估（卖车-评估结果页）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarEvaluation carEvaluation)
    {
        return toAjax(carEvaluationService.updateCarEvaluation(carEvaluation));
    }

    /**
     * 删除卖车评估（卖车-评估结果页）
     */
    @PreAuthorize("@ss.hasPermi('car:evaluation:remove')")
    @Log(title = "卖车评估（卖车-评估结果页）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carEvaluationService.deleteCarEvaluationByIds(ids));
    }
}
